import dayjs from "dayjs";
export const timeFormat = (dateStr: any, type?: string) => {
  switch (type) {
    case "ymd":
      return dayjs(dateStr).format("YYYY-MM-DD");
    case "y2s":
      return dayjs(dateStr).format("YYYY-MM-DD HH:mm:ss");
    default:
      return dayjs(dateStr).format("YYYY-MM-DD");
  }
};
export const timeRangeTransform = (timeRange: Array<any>, params: any) => {
  if (timeRange && timeRange.length > 0) {
    params.value.condition.startTime = timeFormat(timeRange[0], "y2s");
    params.value.condition.endTime = timeFormat(timeRange[1], "y2s");
  } else {
    params.value.condition.startTime = "";
    params.value.condition.endTime = "";
  }
};
// 添加日期范围
export const addDateRange = (
  params: any,
  dateRange: Array<any>,
  propName?: string
) => {
  let search = params;
  search.params =
    typeof search.params === "object" &&
    search.params !== null &&
    !Array.isArray(search.params)
      ? search.params
      : {};
  dateRange = Array.isArray(dateRange) ? dateRange : [];
  if (typeof propName === "undefined") {
    search.params["beginTime"] = dateRange[0];
    search.params["endTime"] = dateRange[1];
  } else {
    search.params["begin" + propName] = dateRange[0];
    search.params["end" + propName] = dateRange[1];
  }
  return search;
};
